/*
Package service
@Time : 2022/12/21 17:47
@Author : 董胜烨
@File : bonus
@Software: GoLand
@note:
*/
package service

import (
	"employee/model"
	"fmt"
)

type Bonus struct {
	Amount     float64 `json:"amount"`
	Date       string  `json:"date"`
	EmployeeID int64   `json:"employee_id"`
	ID         int64   `json:"id"`
}

func (b *Bonus) Insert() bool {
	sqlStr := "INSERT INTO bonus (employee_id, amount, date) VALUES (?,?,?)"
	insertId := model.Insert(sqlStr, b.EmployeeID, b.Amount, b.Date)
	if insertId == 0 {
		return false
	}
	b.ID = insertId
	return true
}
func (b Bonus) Update() bool {
	sqlStr := "UPDATE bonus SET employee_id=?,amount=?,date=? WHERE id=?"
	return model.Update(sqlStr, b.EmployeeID, b.Amount, b.Date, b.ID)
}
func (b Bonus) Delete() bool {
	sqlStr := "DELETE FROM bonus WHERE id=?"
	return model.Delete(sqlStr, b.ID)
}

func (b Bonus) QueryByEmployee() []map[string]string {
	sqlStr := fmt.Sprintf("SELECT * FROM bonus WHERE employee_id='%d'", b.EmployeeID)
	return model.QueryAll(sqlStr)
}
